<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimal-ui"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style"/>
    <meta charset="UTF-8">
    <title>添加物联网网关</title>
    <link rel="stylesheet" type="text/css" href="../static/css/weui.css">
    <link rel="stylesheet" type="text/css" href="../static/css/layui.css" media="all">
    <script src="../static/js/jquery-2.1.4.js"></script>
</head>
<body>
    <ul class="layui-nav" lay-filter="">
        <li class="layui-nav-item"><a href="/home">首页</a></li>
        <li class="layui-nav-item layui-this"><a href="/newband">添加设备</a></li>
        <li class="layui-nav-item"><a href="/airkiss">一键配网</a></li>
    </ul>
    <br>
    <br>
    <br>


    <div id="form1" class="layui-form" >
        <div class="layui-form-item">
            <label class="layui-form-label">网关名称</label>
            <div class="layui-input-inline">
                <input type="text" id="gateway_name" required  lay-verify="required" placeholder="请输入网关名称" autocomplete="on" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">网关编码</label>
            <div class="layui-input-inline">
                <input type="text" id="gateway_id" required lay-verify="required" placeholder="请输入网关唯一编码" autocomplete="on" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" type="button" id="band" value="立即添加" onclick="ajaxRequest()">立即添加
                    <script type="text/javascript">
                        let ajaxRequest = function () {
                            let data = {
                                "gateway_id":$("#gateway_id").val().trim(),
                                "gateway_name": $("#gateway_name").val().trim(),
                                "user_id": {{.userID}}
                            };
                            $.ajax(
                                {
                                    url: "/banddevice",
                                    type: "POST",
                                    dataType: "json",
                                    contentType: "application/json",
                                    data: JSON.stringify(data),
                                    success: function (data) {
                                        if(data.status === 'ok'){
                                            alert("绑定成功：" + data.errmsg);
                                            location.reload();
                                        }
                                        if(data.status === 'error'){
                                            alert("绑定失败："+data.errmsg);
                                        }
                                    },
                                    error: function (data) {
                                        alert("error" + data.errmsg)
                                    }
                                }
                            );
                        }
                    </script>
                </button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </div>
</body>
</html>